
import Controller.*;
import TO.*;
import java.util.*;
import java.util.regex.*;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author admin-pc
 */
public class MainMenu {

    public boolean test(String testString) {
        Pattern p = Pattern.compile("(1|2|0)");
        Matcher m = p.matcher(testString);
        return m.matches();
    }

    public void mainMenu() {
        FillMenu fillMenu = new FillMenu();
        FindMenu findMenu = new FindMenu();

        Application app = new Application();

        FindMainMenuCommand findMainMenuCommand = new FindMainMenuCommand(findMenu);
        FillMainMenuCommand fillMainMenuCommand = new FillMainMenuCommand(fillMenu);
        ExitCommand exitCommand = new ExitCommand();
        System.out.println("1 Заполнение");
        System.out.println("2 Поиск");
        System.out.println("0 Выход");

        app.setCommand(1, fillMainMenuCommand);
        app.setCommand(2, findMainMenuCommand);
        app.setCommand(0, exitCommand);

        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        try {
            int i = Integer.parseInt(str);

            if (test(str)) {
                app.buttonWasPressed(i);
            }
            else {
                System.out.println("\nВведите корректные данные");
                mainMenu();
            }
        }
        catch (Exception e) {
            System.out.println("\nВведите корректные данные");
            mainMenu();
        }

    }

}
